package client.construct.builder;

import org.junit.Test;
import org.xml.sax.SAXException;
import uml.construct.builder.Actor;
import uml.construct.builder.ActorBuilder;
import uml.construct.builder.ActorDirector;
import util.bean.BeanUtil;
import util.xml.XMLUtil;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;

/**
 * 建造者--客户端<br>
 * on 2022/12/17 20:15
 */
public class Client {
    /**
     * 保留指挥者类
     */
    @Test
    public void t() throws ParserConfigurationException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, SAXException {
        ActorDirector director = new ActorDirector();
        ActorBuilder actorBuilder = BeanUtil.newBean(ActorBuilder.class,
                new File("src/main/resources/xml/builder.xml"),
                "actualBuilderName");
        director.build(actorBuilder); // 指挥者负责复杂对象的部件的建造次序
        Actor actor = director.getActor();

        System.out.println("角色类型:" + actor.getType());
        System.out.println(actor.getSex());
        System.out.println(actor.getFace());
        System.out.println(actor.getCustom());
        System.out.println(actor.getHairStyle());
    }

    /**
     * 省略指挥者类
     */
    @Test
    public void t1() throws ParserConfigurationException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, SAXException {
        ActorBuilder actorBuilder = BeanUtil.newBean(ActorBuilder.class,
                new File("src/main/resources/xml/builder.xml"),
                "actualBuilderName");
        actorBuilder.build();// 将指挥者负责的任务封装到建造者内部
        Actor actor = actorBuilder.getActor();

        System.out.println("角色类型:" + actor.getType());
        System.out.println(actor.getSex());
        System.out.println(actor.getFace());
        System.out.println(actor.getCustom());
        System.out.println(actor.getHairStyle());
    }
}
